package com.heima.tanhua.controller;

import com.heima.tanhua.commonResult.Result;
import com.heima.tanhua.dto.UserInfoDto;
import com.heima.tanhua.dto.userDto;
import com.heima.tanhua.dto.PhoneDto;
import com.heima.tanhua.pojo.User;
import com.heima.tanhua.serivce.UserService;
import com.heima.tanhua.vo.LoginVo;
import com.heima.tanhua.vo.RecommendationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/sendMsg")
    public Result sendMsg(@RequestBody PhoneDto phoneDto) {
        boolean res = userService.sendMsg(phoneDto.getPhone());
        if (!res) {
            return Result.error("号码错误");
        }
        return Result.success("手机验证码短信发送成功");
    }

    @PostMapping("login")
    public Result login(@RequestBody userDto dto) {

        LoginVo vo = userService.login(dto);
        return Result.success("登录成功", vo);
    }

    @PutMapping("/info")
    public Result fillUserInfo(@RequestBody UserInfoDto dto) {
        boolean res = userService.fillUserInfo(dto);
        if (!res) {
            return Result.error("修改失败");
        }
        return Result.success("修改成功");
    }

    @PutMapping("/update")
    public Result updateUser(@RequestBody User user) {
        boolean res = userService.updateUser(user);
        if (!res) {
            return Result.error("修改失败");
        }
        return Result.success("修改成功");
    }

    @GetMapping("/recommendation")
    public Result recommendation(@RequestParam Double longitude, @RequestParam Double latitude,
                                 @RequestParam Integer page, @RequestParam Integer pageSize) {
        List<RecommendationVo> recommendationList = userService.getRecommendationList(longitude, latitude, page, pageSize);
        return  Result.success("");
    }

}
